﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorkshopModule.Enums;
using WorkshopModule.Tools;

namespace WorkshopModule.Models {
    [Table("DeviceDetail")]
    public class DeviceDetail : INotifyPropertyChanged {
        //属性变更通知
        public event PropertyChangedEventHandler? PropertyChanged;

        //可以设置一个静态的设备数量

        //设备编号
        private int _DeviceId;
        [Key]
        public int DeviceId {
            get { return _DeviceId; }
            set {
                _DeviceId = value;
                if (PropertyChanged != null) {
                    PropertyChanged(this, new PropertyChangedEventArgs("DeviceId"));
                    PropertyChanged(this, new PropertyChangedEventArgs("MachineName"));
                }
            }
        }
        //设备类型
        private DeviceType deviceType;
        public DeviceType DeviceType {
            get { return deviceType; }
            set {
                deviceType = value;
                if (PropertyChanged != null) {
                    PropertyChanged(this, new PropertyChangedEventArgs("DeviceType"));
                    PropertyChanged(this, new PropertyChangedEventArgs("MachineName"));
                }
            }
        }

        //设备状态
        private DeviceStatus _DeviceStatus;
        public DeviceStatus DeviceStatus {
            get { return _DeviceStatus; }
            set {
                _DeviceStatus = value;
                if (PropertyChanged != null) {
                    PropertyChanged(this, new PropertyChangedEventArgs("DeviceStatus"));
                    PropertyChanged(this, new PropertyChangedEventArgs("Status"));
                    PropertyChanged(this, new PropertyChangedEventArgs("StatusColour"));
                }
            }
        }
        //计划数量
        private uint _PlanAmount;
        public uint PlanAmount {
            get { return _PlanAmount; }
            set {
                _PlanAmount = value;
                if (PropertyChanged != null) {
                    PropertyChanged(this, new PropertyChangedEventArgs("PlanAmount"));
                    PropertyChanged(this, new PropertyChangedEventArgs("Percent"));
                }
            }
        }

        //已完成多少
        private uint _Completed;
        public uint Completed {
            get { return _Completed; }
            set {
                _Completed = value;
                if (PropertyChanged != null) {
                    PropertyChanged(this, new PropertyChangedEventArgs("Completed"));
                    PropertyChanged(this, new PropertyChangedEventArgs("Percent"));
                }
            }
        }

        //所处车间编号
        private uint _WorkShopId;
        public uint WorkShopId {
            get { return _WorkShopId; }
            set {
                _WorkShopId = value;
                if (PropertyChanged != null) {
                    PropertyChanged(this, new PropertyChangedEventArgs("WorkShopId"));
                }
            }
        }

        // 工单编号
        private string _OrderNo;
        public string OrderNo {
            get { return _OrderNo; }
            set {
                _OrderNo = value;
                if (PropertyChanged != null) {
                    PropertyChanged(this, new PropertyChangedEventArgs("OrderNo"));
                }
            }
        }

        // 完成百分比(只读)
        public double Percent {
            get {
                return Completed * 100.0 / PlanAmount;
            }
        }
        //设备名称
        public string MachineName {
            get {
                return EnumDependency.GetEnumDescription(DeviceType) + "-" + DeviceId;
            }
        }

        //设备状态
        public string Status {
            get {
                return EnumDependency.GetEnumDescription(DeviceStatus);
            }
        }
        //状态颜色
        public string StatusColour {
            get {
                if (DeviceStatus == DeviceStatus.Work) return "Blue";
                if (DeviceStatus == DeviceStatus.Wait) return "Orange";
                if (DeviceStatus == DeviceStatus.Halt) return "Gray";
                return "Red";
            }

        }
    }
}
